package ar.com.poo.vista;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import ar.com.poo.controlador.GestionTelefonia;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AltaDeServicio extends javax.swing.JFrame {
	
	private static AltaDeServicio app;
	private JLabel txtNombre;
	private JTextField nombre;
	private JTextField valorUnitario;
	private JLabel texto;
	private JButton cancelar;
	private JButton aceptar;
	private JLabel txtValorUnitario;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AltaDeServicio inst = getInstancia();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public static AltaDeServicio getInstancia() {
		if (app == null)
			app = new AltaDeServicio();
		return app;
	}
	
	private AltaDeServicio() {
		super("Alta de Servicio");
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("Alta de Servicio");
			{
				txtNombre = new JLabel();
				getContentPane().add(txtNombre);
				txtNombre.setText("Nombre:");
				txtNombre.setBounds(45, 84, 70, 16);
			}
			{
				nombre = new JTextField();
				getContentPane().add(nombre);
				nombre.setBounds(153, 81, 180, 23);
			}
			{
				txtValorUnitario = new JLabel();
				getContentPane().add(txtValorUnitario);
				txtValorUnitario.setText("Valor Unitario:");
				txtValorUnitario.setBounds(45, 127, 70, 16);
			}
			{
				valorUnitario = new JTextField();
				getContentPane().add(valorUnitario);
				valorUnitario.setBounds(153, 124, 90, 23);
			}
			{
				aceptar = new JButton();
				getContentPane().add(aceptar);
				aceptar.setText("Aceptar");
				aceptar.setBounds(45, 222, 90, 30);
				aceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						PopUp popUp = PopUp.getInstancia();
						GestionTelefonia sist = GestionTelefonia.getInstancia();
						String mensaje= sist.nuevoServicio(nombre.getText(), Integer.parseInt(valorUnitario.getText()));
						
						popUp.agregarMensaje(mensaje);
						popUp.setVisible(true);					
						
					}
				});
			}
			{
				cancelar = new JButton();
				getContentPane().add(cancelar);
				cancelar.setText("Cancelar");
				cancelar.setBounds(243, 222, 90, 30);
				cancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						app.setVisible(false);
						limpiarPantalla();
					}
				});
			}
			{
				texto = new JLabel();
				getContentPane().add(texto);
				texto.setText("Ingresar los datos del nuevo servicio");
				texto.setBounds(80, 13, 235, 16);
			}
			pack();
			setSize(400, 300);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void limpiarPantalla() {
		nombre.setText("");
		valorUnitario.setText("");
		
	}

}
